package com.zr.gdms.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zr.gdms.model.User;
import com.zr.gdms.service.LoginService;
import com.zr.gdms.serviceimpl.LoginServiceImpl;
/**
 * 验证登录用户名是否正确
 * @author 李培宁
 *
 */
public class LoginValidateControllerLPN extends HttpServlet{

	LoginService ls = new LoginServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String uname = req.getParameter("uname");
		List<User> users = ls.findUserUname();
		boolean flag = false;
		for (User user : users) {
			if (uname.equals(user.getUname())) {
				flag = true;
			}
		}
		
		PrintWriter pw = resp.getWriter();
		if (flag) {
			pw.write("1");
		}else{
			pw.write("0");
		}
	}
}
